<?php
  #--------------------------------------------------
  # ALL INCLUDES + STANDARD-VALUES
  #--------------------------------------------------
  include_once("include/config.inc");
  include_once("include/template.inc");
  include_once("include/class.db.php5");
  include_once("include/class.tools.php5");
  $svo = new db("svoptik");
  $tools = new tool();
  
  include_once("include/banner_xchange.php5");
  include_once("include/global_fix_extern.inc");
  
  #--------------------------------------------------
  # CREATE TEMPLATE
  #--------------------------------------------------
  $t = new Template("templates", "keep");
  $t->set_file(array("page" => "svoptik.tpl",
                     "navi" => "navi.tpl",
                     "news" => "news.tpl"));
  #--------------------------------------------------


  #--------------------------------------------------
  # CREATE NAVIGATION RIGHT
  #--------------------------------------------------
  $links = "";
  $url[0] = array("URL" => "next_games.php5", "URL-TEXT" => "n&auml;chste Spiele", "ONCLICK" => "", "TARGET" => "_self");
  $url[1] = array("URL" => "archive.php5", "URL-TEXT" => "Archiv", "ONCLICK" => "", "TARGET" => "_self");
  for ($i=0; $i<count($url); $i++) {
     $links .= "
        <tr height=\"15\">
			<td valign=\"top\"><img src=\"standard/spacer.gif\" width=\"20\" height=\"15\" border=\"0\" alt=\"\"></td>
			<td valign=\"top\"><a href=\"".$url[$i]['URL']."\" class=\"text\" target=\"".$url[$i]['TARGET']."\" onClick=\"".$url[$i]['ONCLICK']."\">".$url[$i]['URL-TEXT']."</a></td>
			<td valign=\"top\"><img src=\"standard/spacer.gif\" width=\"20\" height=\"15\" border=\"0\" alt=\"\"></td>
		</tr>
		<tr height=\"15\">
            <td colspan=\"3\"><img src=\"standard/spacer.gif\" width=\"20\" height=\"15\" border=\"0\" alt=\"\"></td>
		</tr>
       ";
  }
  $t->set_var(array("LINKS" => $links, "BANNER" => $banner));
  $right_nav = $t->parse("","navi", true);
  #--------------------------------------------------


  #--------------------------------------------------
  # CREATE CONTENT "NEWS"
  #--------------------------------------------------
  $content = "";
  $test = "select * from ".$table['Berichte']." order by date desc limit 5;";
  $sql = $svo->doSQL($test);

  while ($tupel = $svo->getRecordset($sql)) {
      if (strlen($tupel['text']) > 250) $link   = "... <a href=\"show_report.php5?id=".$tupel['report_id']."\" class=\"news\">mehr</a>";
      else $link = "&nbsp";
      $auth   = $svo->readRecordset("select * from ".$table['User']." where usr_id='".$tupel['author_id']."';");
      $author = "<a href=\"mailto:".$auth['usr_email']."\" class=\"news\">".$auth['usr_vname']." ".$auth['usr_name']."</a>";

      $t->set_var(array("LINK"      => $link,
                        "KATEGORIE" => $tools->html_replace($tupel['cat'])." ".$tools->html_replace($tupel['team']),
                        "HEADLINE"  => $tools->html_replace($tupel['headline']),
                        "DATUM"     => $tools->show_date($tupel['date'],'date_only'),
                        "TEXT"      => substr($tools->html_replace($tupel['text']),0,250),
                        "AUTHOR"    => $author,
                        "ANCHOR"    => $tupel['report_id']));
      $content .= $t->parse("", "news", true);
  }
  #--------------------------------------------------

  #--------------------------------------------------
  # PARSE & OUTPUT
  #--------------------------------------------------
  $t->set_var(array("sitenav" => "NEWS",
                    "content" => $content."<br>",
                    "navi" => $right_nav,
	"SYNCHRONIZE" => " "));

  $t->parse("ALL", "page", true);
  $t->p("ALL");
?>
